package com.newtouch.bxzs.policy.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import com.newtouch.bxzs.policy.config.MyLog;
import com.newtouch.bxzs.policy.model.bo.PreservationBO;
import com.newtouch.bxzs.policy.model.bo.family.*;
import com.newtouch.bxzs.policy.model.vo.*;
import com.newtouch.bxzs.policy.model.vo.family.*;
import com.newtouch.bxzs.policy.service.FamilyPolicyService;
import com.newtouch.bxzs.policy.util.PolicyListPageUtils;
import com.newtouch.bxzs.policy.util.QueryCriteriaUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 家庭单管理controller层
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 10:12</td>
 * <td>linhongxi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author linhongxi
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "家庭单管理")
@RestController
@SuppressWarnings("unchecked")
@RequestMapping("/familyPolicy")
public class FamilyPolicyController {
    /** 静态变量：系统日志 */
    private static final Log logger = LogFactory.getLog(FamilyPolicyController.class);

    @Resource
    private FamilyPolicyService familyPolicyService;

    @ApiOperation(value = "查询家庭单列表")
    @PostMapping("/getFamilyPolicyList")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getFamilyPolicyList",userOperationType = 4,userOperationSummary = "查询家庭单列表")
    public BaseResponse<FamilyPolicyBO> familyPolicyList(@RequestBody FamilyPolicyVO familyPolicyVO) {
        logger.info("查询家庭单列表");
       return RespGenerator.returnOK(familyPolicyService.getFamilyPolicyList(familyPolicyVO));
    }

    @ApiOperation(value = "根据保单号调用外部接口查询家庭单详情")
    @PostMapping("/getFamilyPolicyInfo")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/geFamilyPolicyInfo",userOperationType = 4,userOperationSummary = "查询家庭单详情")
    public BaseResponse<FamilyPolicyBO> familyPolicyInfo(@RequestBody PolicyInfoVO policyInfoVO) {
        logger.info("查询家庭单保单详情");
        return RespGenerator.returnOK(familyPolicyService.getFamilyPolicyInfo(policyInfoVO));
    }

    @ApiOperation(value = "根据保单号调用外部接口查询家庭单保全信息")
    @PostMapping(value = "/getFamilyPolicyPreservation")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getFamilyPolicyPreservation",userOperationType = 4,userOperationSummary = "查询家庭单保全信息")
    public BaseResponse<PreservationBO> familyPolicyPreservation(@RequestBody PolicyInfoPageVO policyInfoPageVO) {
        logger.info("调用查询家庭单保全信息外部接口");
        List<PreservationBO> preservationListBO = familyPolicyService.getFamilyPolicyPreservation(policyInfoPageVO);
        if(!CollectionUtil.isEmpty(preservationListBO)){
            //对获取的保全信息进行分页处理
            PolicyListPageUtils<PreservationBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(preservationListBO,policyInfoPageVO.getPageSize(),policyInfoPageVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(preservationListBO);
    }

    @ApiOperation(value = "根据保单号调用外部接口查询家庭单理赔信息")
    @PostMapping(value = "/getFamilyPolicyClaims")
    @MyLog(systemFunctionName = "家庭单保单管理",systemFunctionUrl = "/familyPolicy/getFamilyPolicyClaims",userOperationType = 4,userOperationSummary = "查询家庭单理赔信息")
    public BaseResponse<FamilyClaimsBO> familyPolicyClaims(@RequestBody PolicyInfoPageVO policyInfoPageVO) {
        logger.info("调用查询家庭单理赔信息外部接口");
        List<FamilyClaimsBO> familyClaimsListBO = familyPolicyService.getPolicyClaims(policyInfoPageVO);
        if(!CollectionUtil.isEmpty(familyClaimsListBO)){
            //对获取的理赔信息进行分页处理
            PolicyListPageUtils<FamilyClaimsBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(familyClaimsListBO,policyInfoPageVO.getPageSize(),policyInfoPageVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(familyClaimsListBO);
    }

    @ApiOperation(value = "根据保单号调用外部接口查询家庭单人员清单信息")
    @PostMapping(value = "/getFamilyPolicyUserList")
    @MyLog(systemFunctionName = "家庭单保单管理",systemFunctionUrl = "/familyPolicy/getFamilyPolicyUserList",userOperationType = 4,userOperationSummary = "查询家庭单人员清单信息")
    public BaseResponse<PolicyUserListBO> familyPolicyUserList(@RequestBody PolicyUserListVO policyUserListVO) {
        logger.info("查询家庭单人员清单接口");
        List<PolicyUserListBO> policyUserListBO = familyPolicyService.getFamilyPolicyUserList(policyUserListVO);
        if(!CollectionUtil.isEmpty(policyUserListBO)){
            //对获取的人员清单信息进行分页处理
            PolicyListPageUtils<PolicyUserListBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(policyUserListBO,policyUserListVO.getPageSize(),policyUserListVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(policyUserListBO);
    }

    @ApiOperation(value = "查询家庭单保全进度列表")
    @PostMapping(value = "/getPreservationListByFamilyPolicy")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getPreservationListByFamilyPolicy",userOperationType = 4,userOperationSummary = "查询家庭单保全进度列表")
    public BaseResponse<FamilyPreservationProgressInfoBO> preservationListByFamilyPolicy(@RequestBody FamilyPreservationVO familyPreservationVO) {
        logger.info("查询家庭单保全进度列表");
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(familyPreservationVO.getApplicationStartDate(),familyPreservationVO.getApplicationDeadline());
        List<FamilyPreservationProgressInfoBO> familyPreservationListBO = familyPolicyService.getPreservationListByFamilyPolicy(familyPreservationVO);
        if(!CollectionUtil.isEmpty(familyPreservationListBO)){
            //对获取的保全进度列表信息进行分页处理
            PolicyListPageUtils<FamilyPreservationProgressInfoBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(familyPreservationListBO,familyPreservationVO.getPageSize(),familyPreservationVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(familyPreservationListBO);
    }

    @ApiOperation(value = "通知跳转家庭单保全进度列表")
    @PostMapping(value = "/getPreservationListByFamilyPolicyNotice")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getPreservationListByFamilyPolicyNotice",userOperationType = 4,userOperationSummary = "通知跳转家庭单保全进度列表")
    public BaseResponse<FamilyPreservationProgressInfoBO> preservationListByFamilyPolicyNotice(@RequestBody FamilyPreservationVO familyPreservationVO) {
        logger.info("通知跳转家庭单保全进度列表");
        return RespGenerator.returnOK(familyPolicyService.getPreservationListByFamilyPolicy(familyPreservationVO));
    }

    @ApiOperation(value = "查看家庭单保全进度详情")
    @PostMapping(value = "/getPreservationInfoByFamilyPolicy")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getPreservationInfoByFamilyPolicy",userOperationType = 4,userOperationSummary = "查看家庭单保全进度详情")
    public BaseResponse<FamilyPreservationProgressInfoBO> preservationInfoByFamilyPolicy(@RequestBody PreservationProgressInfoVO PreservationProgressInfoVO) {
        logger.info("查看家庭单保全进度详情");
        return RespGenerator.returnOK(familyPolicyService.getPreservationInfoByFamilyPolicy(PreservationProgressInfoVO));
    }

    @ApiOperation(value = "查询家庭单理赔进度列表")
    @PostMapping(value = "/getClaimsProgressListByFamilyPolicy")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getClaimsProgressListByFamilyPolicy",userOperationType = 4,userOperationSummary = "查询家庭单理赔进度列表")
    public BaseResponse<FamilyClaimsBO> claimsProgressListByFamilyPolicy(@RequestBody FamilyClaimsVO familyClaimsVO) {
        logger.info("查询家庭单理赔进度列表");
        List<FamilyClaimsBO> familyClaimsProgressBO = familyPolicyService.getClaimsProgressListByFamilyPolicy(familyClaimsVO);
        if(!CollectionUtil.isEmpty(familyClaimsProgressBO)){
            //对获取的理赔进度信息进行分页处理
            PolicyListPageUtils<FamilyClaimsBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(familyClaimsProgressBO,familyClaimsVO.getPageSize(),familyClaimsVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(familyClaimsProgressBO);
    }

    @ApiOperation(value = "查看家庭单新契约详情")
    @PostMapping(value = "/getNewContractInfoByFamilyPolicy")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getNewContractInfoByFamilyPolicy",userOperationType = 4,userOperationSummary = "查看家庭单新契约详情")
    public BaseResponse<FamilyPolicyNewContractBO> newContractInfoByFamilyPolicy(@RequestBody PolicyNewContractInfoVO policyNewContractInfoVO) {
        logger.info("查看家庭单新契约详情");
        return RespGenerator.returnOK(familyPolicyService.getNewContractInfoByFamilyPolicy(policyNewContractInfoVO));
    }

    @ApiOperation(value = "查询家庭单新契约列表")
    @PostMapping(value = "/getNewContractListByFamilyPolicy")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getNewContractListByFamilyPolicy",userOperationType = 4,userOperationSummary = "查询家庭单新契约列表")
    public BaseResponse<FamilyPolicyNewContractBO> newContractListByFamilyPolicy(@RequestBody FamilyPolicyNewContractVO familyPolicyNewContractVO) {
        logger.info("查询家庭单新契约列表");
        List<FamilyPolicyNewContractBO> familyPolicyNewContractListBO = familyPolicyService.getNewContractListByFamilyPolicy(familyPolicyNewContractVO);
        if(!CollectionUtil.isEmpty(familyPolicyNewContractListBO)){
            //对获取的新契约保单信息进行分页处理
            PolicyListPageUtils<FamilyPolicyNewContractBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(familyPolicyNewContractListBO,familyPolicyNewContractVO.getPageSize(),familyPolicyNewContractVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(familyPolicyNewContractListBO);
    }

    @ApiOperation(value = "查询家庭单新契约详情人员清单信息")
    @PostMapping(value = "/getNewContractUserListByFamilyPolicy")
    @MyLog(systemFunctionName = "家庭单保单管理",systemFunctionUrl = "/familyPolicy/getNewContractUserListByFamilyPolicy",userOperationType = 4,userOperationSummary = "查询家庭单新契约人员清单信息")
    public BaseResponse<PolicyUserListBO> newContractUserListByFamilyPolicy(@RequestBody FamilyPolicyNewContractInfoVO familyPolicyNewContractInfoVO) {
        logger.info("查询家庭单新契约详情人员清单信息");
        List<PolicyUserListBO> policyUserListBO = familyPolicyService.getNewContractUserListByFamilyPolicy(familyPolicyNewContractInfoVO);
        if(!CollectionUtil.isEmpty(policyUserListBO)){
            //对获取的人员清单信息进行分页处理
            PolicyListPageUtils<PolicyUserListBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(policyUserListBO,familyPolicyNewContractInfoVO.getPageSize(),familyPolicyNewContractInfoVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(policyUserListBO);
    }

    @ApiOperation(value = "查询家庭单满期列表")
    @PostMapping(value = "/getExpirationPolicyListByFamilyPolicy")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getExpirationPolicyListByFamilyPolicy",userOperationType = 4,userOperationSummary = "查询家庭单满期列表")
    public BaseResponse<FamilyExpirationPolicyBO> expirationPolicyListByFamilyPolicy(@RequestBody FamilyExpirationPolicyVO familyExpirationPolicyVO) {
        logger.info("查询家庭单满期信息列表");
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(familyExpirationPolicyVO.getExpirationStartDate(),familyExpirationPolicyVO.getExpirationDeadline());
        List<FamilyExpirationPolicyBO> expirationPolicyBO = familyPolicyService.getExpirationPolicyListByFamilyPolicy(familyExpirationPolicyVO);
        if(!CollectionUtil.isEmpty(expirationPolicyBO)){
            //对获取的满期数据进行分页处理
            PolicyListPageUtils<FamilyExpirationPolicyBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(expirationPolicyBO,familyExpirationPolicyVO.getPageSize(),familyExpirationPolicyVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(expirationPolicyBO);
    }

    @ApiOperation(value = "通知跳转家庭单满期列表")
    @PostMapping(value = "/getExpirationPolicyListByFamilyPolicyNotice")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getExpirationPolicyListByFamilyPolicyNotice",userOperationType = 4,userOperationSummary = "通知跳转家庭单满期列表")
    public BaseResponse<FamilyExpirationPolicyBO> expirationPolicyListByFamilyPolicyNotice(@RequestBody FamilyExpirationPolicyVO familyExpirationPolicyVO) {
        logger.info("通知跳转家庭单满期列表");
        return RespGenerator.returnOK(familyPolicyService.getExpirationPolicyListByFamilyPolicy(familyExpirationPolicyVO));
    }

    @ApiOperation(value = "查询家庭单续期列表")
    @PostMapping(value = "/getRenewalPolicyListByFamilyPolicy")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getRenewalPolicyListByFamilyPolicy",userOperationType = 4,userOperationSummary = "查询家庭单续期列表")
    public BaseResponse<FamilyRenewalPolicyBO> renewalPolicyListByFamilyPolicy(@RequestBody FamilyRenewalPolicyVO familyRenewalPolicyVO) {
        logger.info("查询家庭单续期信息列表");
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(familyRenewalPolicyVO.getPaymentStartDate(),familyRenewalPolicyVO.getPaymentDeadline());
        List<FamilyRenewalPolicyBO> renewalPolicyListBO = familyPolicyService.getRenewalPolicyListByFamilyPolicy(familyRenewalPolicyVO);
        if(!CollectionUtil.isEmpty(renewalPolicyListBO)){
            PolicyListPageUtils<FamilyRenewalPolicyBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(renewalPolicyListBO,familyRenewalPolicyVO.getPageSize(),familyRenewalPolicyVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(renewalPolicyListBO);
    }
    @ApiOperation(value = "通知跳转家庭单续期列表")
    @PostMapping(value = "/getRenewalPolicyListByFamilyPolicyNotice")
    @MyLog(systemFunctionName = "家庭单管理",systemFunctionUrl = "/familyPolicy/getRenewalPolicyListByFamilyPolicyNotice",userOperationType = 4,userOperationSummary = "通知跳转家庭单续期列表")
    public BaseResponse<FamilyRenewalPolicyBO> renewalPolicyListByFamilyPolicyNotice(@RequestBody FamilyRenewalPolicyVO familyRenewalPolicyVO) {
        logger.info("通知跳转家庭单续期列表");
        return RespGenerator.returnOK(familyPolicyService.getRenewalPolicyListByFamilyPolicy(familyRenewalPolicyVO));
    }
}
